import request from "@/service/request";
import requestAly from '@/service/requestAly'
import {
  ClientCommentVo, CommentNode, CourseAgeVo, CourseCategoryVo,
  CourseCourseVo,
  CourseIdRequest, CourseLabelVo, CourseResourceVo, CourseSceneVo,
  CourseSectionVo,
  SysExamineTaskVo, VodPlayAuth, VodUploadAuth
} from "@/service/api/course/message/types.ts";
import {PromisePageResponse, PromiseResponse} from "@/service/api/type.ts";

/**
 * 获取课程列表
 * @param query
 */
const getCourseList = (query: any): PromisePageResponse<CourseCourseVo> => {
  return request({
    url: "/course/course/list",
    method: "get",
    params: query,
  });
};

/**
 * 根据场景id获取一级分类列表
 * @param sceneId
 */
const getFirstCategoryListByScene = (sceneId: string): PromiseResponse<Array<CourseCategoryVo>> => {
  return request({
    url: `/course/category/listByScene/${sceneId}`,
    method: "get",
  });
};

/**
 * 获取课程详情
 * @param courseId
 */
const getCourseDetail = (courseId: string): PromiseResponse<CourseCourseVo> => {
  return request({
    url: `/course/course/${courseId}`,
    method: "get",
  });
};

/**
 * 根据分类的id获取标签
 * @param categoryId
 */
const getLabelsByCategoryId = (categoryId: string): PromiseResponse<Array<CourseLabelVo>> => {
  return request({
    url: "/course/label/listByCategory/" + categoryId,
    method: "get",
  });
};

/**
 * 获取年龄列表
 * @param query
 */
const getAgeList = (query: any): PromisePageResponse<CourseAgeVo> => {
  return request({
    url: "/course/age/page",
    method: "get",
    params: query,
  });
};

// 获取场景分类列表
const getSceneList = (): PromisePageResponse<CourseSceneVo> => {
  return request({
    url: "/course/scene/list",
    method: "get",
  });
};

/**
 * 获取章节列表
 * @param query
 */
const getSectionList = (query: CourseIdRequest): PromisePageResponse<CourseSectionVo> => {
  return request({
    url: "/course/section/list",
    method: "get",
    params: query,
  });
};

// 私有资源
const getSelfCourseResource = (query: any) => {
  return request({
    url: "/course/resource/self/list",
    method: "get",
    params: query,
  });
};

// 公共资源
const getPublicCourseResource = (query: any) => {
  return request({
    url: "/course/resource/open/list",
    method: "get",
    params: query,
  });
};

// 所有资源（管理员）
const getAllCourseResource = (query: any): PromisePageResponse<CourseResourceVo> => {
  return request({
    url: "/course/resource/list",
    method: "get",
    params: query,
  });
};

/**
 * 获取播放凭证
 * @param vid
 */
const getPlayAuth = (vid: string): PromiseResponse<VodPlayAuth> => {
  return request({
    url: `/course/resource/play/${vid}`,
    method: "get",
  });
};

/**
 * 获取章节下的评论列表
 * @param query
 */
const getSectionCommentList = (query: any): PromisePageResponse<CommentNode> => {
  return request({
    url: "/client/comment/treeselect",
    method: "get",
    params: query,
  });
};

// 删除课程
const  deleteCourse = (id: string | string[]): PromiseResponse<any> => {
  return request({
    url: `/course/course/${id}`,
    method: "delete",
  });
}

// 获取凭证
const getOssAuth = (query: any) => {
  return request({
    url: "/system/oss/uploadAuth",
    method: "get",
    params: query
  });
};

/**
 * 文件上传到OSS
 * @param File
 */
const postToOSS = (File: any) => {
  return requestAly({
    url: ``,
    method: "post",
    data: File,
  });
};

/**
 * 获取章节详情
 * @param sectionId
 */
const getSectionDetail = (sectionId: string): PromiseResponse<CourseSectionVo> => {
  return request({
    url: `/course/section/${sectionId}`,
    method: "get",
  });
}

/**
 * 更新章节信息
 * @param query
 */
const updateSection = (query: any): PromiseResponse<any> => {
  return request({
    url: "/course/section/edit",
    method: "put",
    data: query
  });
}

// 获取评论详情
const getCommentDetail = (id: string) => {
  return request({
    url: "/client/comment/"+id,
    method: "get",
  });
}

/**
 * 新增评论
 * @param query
 */
const addComment = (query: any): PromiseResponse<ClientCommentVo> => {
  return request({
    url: '/client/comment',
    method: 'post',
    data: query
  })
}

/**
 * 删除评论
 * @param commentId
 */
const deleteComment = (commentId: string): PromiseResponse<any> => {
  return request({
    url: `/client/comment/${commentId}`,
    method: "delete",
  });
}

// 修改绑定课程介绍
const linkImg = (query: any) => {
  return request({
    url: "/course/course/img",
    method: "post",
    data: query
  });
}

// 修改绑定课程介绍
const editLinkImg = (query: any) => {
  return request({
    url: "/course/course/img",
    method: "put",
    data: query
  });
}

/**
 * 删除课程章节
 * @param sectionId
 */
const deleteSection = (sectionId: string): PromiseResponse<any> => {
  return request({
    url: `/course/section/${sectionId}`,
    method:'delete'
  });
}
// 提交审核
const handleAddCheck = (id: string) => {
  return request({
    url: `/course/course/examine?courseId=${id}`,
    method: "post",
  });
}

// 弥补被驳回的课程
const handleRemedyCheck = (id: string) => {
  return request({
    url: `/course/course/remedy?courseId=${id}`,
    method: "post",
  });
}

/**
 * 获取评论下全部二级评论
 * @param commentId
 * @param query
 */
const getMoreComment = (commentId: string , query: any): PromisePageResponse<ClientCommentVo> => {
  return request({
    url: `/client/comment/reply/${commentId}`,
    method: "get",
    params: query
  });
};

/**
 * 新增课程
 * @param query
 */
const addCourse = (query: any): PromiseResponse<string> => {
  return request({
    url: "/course/course",
    method: "post",
    data: query,
  });
};

/**
 * 修改课程详情
 * @param query
 */
const  editCourseDetail = (query: any): PromiseResponse<any> => {
  return request({
    url: "/course/course/edit",
    method: "put",
    data: query
  });
};

/**
 * 新增章节
 * @param query
 */
const addSection = (query: any): PromiseResponse<any> => {
  return request({
    url: "/course/section",
    method: "post",
    data: query
  });
};

// 获取审核记录
const getCheckRecord = (query: any): PromisePageResponse<SysExamineTaskVo> => {
  return request({
    url: "/system/examineTask/list",
    method: "get",
    params: query
  });
}

// 绑定封面
const linkCover = (query: any) => {
  return request({
    url: `/course/course/cover?courseId=${query.courseId}&type=${query.type}&url=${query.url}`,
    method: "put",
  });
}

// 交换章节
const exchange = (query: any): PromiseResponse<any> => {
  return request({
    url: '/course/section/exchange',
    method: "post",
    params: query
  });
}

// 获取key
const getUploadAuth = (query: any): PromiseResponse<VodUploadAuth> => {
  return request({
    url: "/course/resource",
    method: "post",
    data: query,
  });
};

// 终止审核
const cancelCheck = (courseId: string) => {
  return request({
    url: "/course/course/terminate/"+courseId,
    method: "post",
  });
}

/**
 * 获取所有标签
 * @param query
 */
const getCapacityLabelList = (query: any): PromisePageResponse<CourseLabelVo> => {
  return request({
    url: "/course/label/list",
    method: "get",
    params: query,
  });
};
/**
 * 修改课程状态
 * @param query 
 * @returns 
 */
const switchCourse = (query: any): PromisePageResponse<any> => {
  return request({
    url: "/course/course/changeStatus",
    method: "put",
    data: query,
  });
}

export {
  getCourseList,
  getCourseDetail,
  getAgeList,
  getSceneList,
  getSectionList,
  getPlayAuth,
  getSectionCommentList,
  getFirstCategoryListByScene,
  getLabelsByCategoryId,
  deleteCourse,
  postToOSS,
  getOssAuth,
  getSectionDetail,
  getSelfCourseResource,
  getPublicCourseResource,
  getAllCourseResource,
  updateSection,
  getCommentDetail,
  addComment,
  deleteComment,
  linkImg,
  handleAddCheck,
  addCourse,
  editCourseDetail,
  addSection,
  getCheckRecord,
  linkCover,
  editLinkImg,
  deleteSection,
  handleRemedyCheck,
  getMoreComment,
  exchange,
  getUploadAuth,
  cancelCheck,
  getCapacityLabelList,
  switchCourse
};
